package cn.bonoon.kernel.support.services.handler;

import javax.persistence.EntityManager;

import cn.bonoon.entities.RecycleEntity;
import cn.bonoon.kernel.events.OperateEvent;
import cn.bonoon.kernel.support.entities.EntityRecyclable;
import cn.bonoon.kernel.support.entities.Persistable;

public class DeleteRecyclableHandler extends DeleteDeletableHander{
	
	@Override
	public void handler(EntityManager entityManager, OperateEvent event, Persistable entity) {
		EntityRecyclable er = (EntityRecyclable) entity;
		RecycleEntity recycle = new RecycleEntity();
		recycle.setEntityId(er.getId());
		recycle.setEntityName(er.getClass().getName());
		recycle.setName(er.getName());
		recycle.setCreateAt(event.now());
		recycle.setCreatorId(event.getId());
		recycle.setCreatorName(event.getUsername());
		recycle.setOwnerId(event.getOwnerId());
		entityManager.persist(recycle);
		super.handler(entityManager, event, entity);
	}
}
